
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:my_flu01/page/card_builder.dart';
import 'package:my_flu01/page/foreachView.dart';
import 'package:my_flu01/page/gridView.dart';
import 'package:my_flu01/page/homePage.dart';
import 'package:my_flu01/page/index.dart';
import 'package:my_flu01/page/index_main.dart';
import 'package:my_flu01/page/listView.dart';
import 'package:my_flu01/page/listView_builder.dart';
import 'package:my_flu01/page/login/index.dart';
import 'package:my_flu01/page/member/addresses.dart';
import 'package:my_flu01/page/member/password.dart';
import 'package:my_flu01/page/member/setting.dart';
import 'package:my_flu01/page/uidemo/FriendCircle.dart';
import 'package:my_flu01/page/uidemo/myUI01.dart';
import 'package:my_flu01/page/mybuttonPage.dart';
import 'package:my_flu01/page/tableView.dart';
import 'package:my_flu01/page/test.dart';
import 'package:my_flu01/page/user.dart';

import 'models/PetCardViewModel.dart';
// install command:  flutter pub add go_router
// anther sept defer return MaterialApp.router(_router)
// how to use? GoRouter.of(context).push('/feedback');  https://blog.51cto.com/u_13272819/6406481
final router = GoRouter(
  initialLocation: '/',
  routes: [
    GoRoute(
      name: 'index', // Optional, add name to your routes. Allows you navigate by name instead of path
      path: '/',
      builder: (context, state) => IndexMain(),
    ),
    GoRoute(
      name: 'home',
      path: '/home',
      builder: (context, state) {
       // final id = state.params['id'] // Get "id" param from URL
        // final search = state.queryParams['search']; // query param from URL
        return HomePage(text: "text", map: new Map());
      },
    ),
    GoRoute(
    name: 'login',
    path: '/login',
    builder: (context, state) => LoginIndexPage(),
    ),
    GoRoute(
      name: 'user',
      path: '/user',
      builder: (context, state) => User(),
    ), GoRoute(
      name: 'button',
      path: '/button',
      builder: (context, state) => MyButtonPage(),
    ),
    GoRoute(
      name: 'listview',
      path: '/listview',
      builder: (context, state) => ListViewPage(),
    ),  GoRoute(
      name: 'foreachView',
      path: '/foreachView',
      builder: (context, state) => foreachViewPage(),
    ),
    GoRoute(
      name: 'ListViewBuilderPage',
      path: '/ListViewBuilderPage',
      builder: (context, state) => ListViewBuilderPage(),
    ), GoRoute(
      name: 'test',
      path: '/test',
      builder: (context, state) => testPage(),
    ),
    GoRoute(
      name: 'card',
      path: '/card',
      builder: (context, state) {
        Map<String,String> maps = state.queryParameters;//接收参数
        if(maps==null || maps.isEmpty){
          maps=new Map();
          maps["id"]="90";
        }

        print(maps);
        return CardViewBuilderPage( id: maps["id"].toString(),);}
    ), GoRoute(
      name: 'gridView',
      path: '/gridView',
      builder: (context, state) => gridViewPage(),
    ),GoRoute(
      name: 'tableview',
      path: '/tableview',
      builder: (context, state) => tableViewPage(),
    ),GoRoute(
      name: 'myui01',
      path: '/myui01',
      builder: (context, state) {
        PetCardViewModel pe = new PetCardViewModel("https://www.itying.com/images/flutter/5.png",
        "https://www.itying.com/images/flutter/2.png","laich","建议--description","topic","2023-01-01 10:10:21",
            "通过这块区域的UI练习，我们可以实践Container组件设置不同的borderRadius，以及Text组件文本内容超出时的截断处理",23, 25,100);
        return myUI01Page(data: pe); },
    ),GoRoute(
      name: 'friendCircle',
      path: '/friendCircle',
      builder: (context, state) {
        return const FriendCirclePage();
      }
    ),GoRoute(
      name: '/member/addresses',
      path: '/member/addresses',
      builder: (context, state) => AddressesPage(),
    ),GoRoute(
      name: '/setting',
      path: '/setting',
      builder: (context, state) => SettingPage(),
    ),GoRoute(
      name: '/member/password',
      path: '/member/password',
      builder: (context, state) => PasswordPage(),
    ),
  ],
);

//然后，我们就可以通过MaterialApp.router或CupertinoApp.router构造函数来使用 GoRouter，并且将 routerConfig 参数设置为我们前面定义的 GoRouter 配置对象。
class MyAppRouter extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      routerConfig: router,
    );
  }
}
